﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ServerPlatform.Web;
using ServerPlatform.Exceptions;
using MapEntities;

namespace WebApp.Controls
{
    public partial class SymbolBindingRuleEditor : BaseDataEditor<SymbolItemBindingRule>
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public override void Edit(SymbolItemBindingRule item)
        {
            base.Edit(item);
            ctlItemEditor.Edit(item);
            SymbolBehaviourEditor1.Edit(item.Behaviour);
            SymbolVisualizationEditor1.Edit(item.Visualization);

        }

        public override SymbolItemBindingRule EndEdit()
        {
            SymbolItemBindingRule itemRule = ctlItemEditor.EndEdit() as SymbolItemBindingRule;
            itemRule.Visualization = SymbolVisualizationEditor1.EndEdit();
            itemRule.Behaviour = SymbolBehaviourEditor1.EndEdit();
            if (string.IsNullOrEmpty(ctlLongitudeField.Text.Trim()) || string.IsNullOrEmpty(ctlLatitudeField.Text.Trim()))
            {
                BusinessException ee = new BusinessException("Longitude Field and Latitude Field cannot be empty");
                throw ee;
            }
            else
            {
                itemRule.LongitudeField = ctlLongitudeField.Text.Trim();
                itemRule.LatitudeField = ctlLatitudeField.Text.Trim();
            }
            return itemRule;
        }

        public override void ClearCurrent()
        {
            ctlItemEditor.ClearCurrent();
            base.ClearCurrent();
        }

        protected override void ShowEntity(SymbolItemBindingRule entity)
        {

            ctlLatitudeField.Text = entity.LatitudeField;
            ctlLongitudeField.Text = entity.LongitudeField;            

        }

        public override SymbolItemBindingRule GetEntity()
        {
            return Current;
        }
    }
}